﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
/*
  insert types
  ray

*/
namespace APIDataManage
{
    public class TypesXML
    {
        public void insertXmlToDB()
        {
            APIDataFunction api = new APIDataFunction();
            XmlDocument doc = api.getTypes();
            if (doc != null)
            {
                XmlElement root = doc.DocumentElement;
                StringBuilder sb = new StringBuilder();
                foreach (XmlNode node in root.ChildNodes)
                {
                    sb.AppendFormat("if not exists (select * from [dbo].[BoatType] where boat_type = '{0}' ) begin insert into BoatType (boat_type,createdate) values ('{1}','{2}') end;", node.Attributes["type"].Value.ToString(), node.Attributes["type"].Value.ToString(), DateTime.Now.ToString());
                }
                if (sb.Length > 0)
                {
                    SqlDbHelper.ExecteNonQuery(sb.ToString(), null);
                }
            }
        }
    }
}
